<div>
    <fieldset>
        <legend>Атрибуты</legend>

        <?php echo $this->AllFieldList()->ToHtml(); ?>
    </fieldset>

    <div class="ControlPanel">
        <button id="AddField">Добавить</button>
        <button id="CloseAddFieldDialog">Закрыть</button>
    </div>


    <script type="text/javascript">
        jsun.run(function() {
        //////////////////////////////////////////////////////

        jsun("#AddField").jsun.event({ onclick: AddField });
        jsun("#CloseAddFieldDialog").jsun.event({ onclick: CloseDialog });
        jsun("#FieldListBox").jsun.event({ ondblclick: AddField });

        function AddField() {

            var table = jsun("#FieldList"),
                field_set = jsun("#FieldSet"),
                listbox = jsun("#FieldListBox"),
                num_row = field_set.getAttribute("data-count"),
                param = "U=Lib&m=Lib\\Edition/FormFieldRow"
                    + "&field_id=" + listbox.value
                    + "&num_row=" + num_row;

            jsun.json.load(function(p) {
                table.firstChild.appendChild(jsun.dom.from_json(p));
                jsun("#A_" + num_row).jsun.event(
                    { onclick: jsun.swap['AddEdit']['LoadDict'] });
                var cls = jsun("#Load_" + num_row);
                if (cls) cls.jsun.event(
                    { onclick: jsun.swap['AddEdit']['LoadFile'] });
            }, param);

            field_set.value += "," + listbox.value;
            field_set.setAttribute("data-count", parseInt(num_row) + 1);
        }

        function CloseDialog() {
            return jsun.dialog.active.close();
        }

        ///////////////////////////////////////////////////////
        });
    </script>
</div>